LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;

-- Dummy_XMT
-- 
-- Inputs:
-- clk = The clock.
-- reset = The reset signal.
-- FWD_to_XMT_DATA = Data being sent to XMT.
-- FWD_to_XMT_ACK = Indicator that data is now being sent to XMT.
-- FWD_to_XMT_DONE = Indicator that we are done sending data now.
-- FWD_to_XMT_LENGTH = The length of FWD's message to XMT.
--
-- Outputs:
-- XMT_to_FWD_spaceavailable = Current space available in the XMT buffer.
-- XMT_to_FWD_ACK = Confirmation that a signal was received last cycle.
--
-- This is a dummy XMT for testing purposes. It sends us ACKs the cycle after we ACK it, and then pretends to receive
-- our data until we tell it we're out of information. To see how this is behaving, I have printouts of the waveform
-- files in Dummy_XMT_operationtiming.png and Dummy_XMT_operationtiming2.png. Really though, it's just a TFF.

ENTITY Dummy_XMT IS
   PORT(
	   clk, reset			 	 	 : IN STD_LOGIC;
	   IN_FWD_to_XMT_ACK	 	 	 : IN STD_LOGIC;
	   IN_FWD_to_XMT_DATA	 	 	 : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
	   IN_FWD_to_XMT_LENGTH 	 	 : IN STD_LOGIC_VECTOR(10 DOWNTO 0);
	   IN_FWD_to_XMT_DONE		 	 : IN STD_LOGIC;
       OUT_XMT_to_FWD_ACK		 	 : OUT STD_LOGIC;
       OUT_XMT_to_FWD_spaceavailable : OUT STD_LOGIC_VECTOR(10 DOWNTO 0)
       );
END Dummy_XMT;

ARCHITECTURE dummy_xmt_arch OF Dummy_XMT IS

COMPONENT ToggleFlipFlop IS
	PORT
	(
		aclr		: IN STD_LOGIC ;
		clock		: IN STD_LOGIC ;
		q		: OUT STD_LOGIC 
	);
END COMPONENT;

BEGIN

-- Echo whatever FWD says in the next clock cycle. Don't ACK me until I tell you I'm done or
-- I'm going to send you another message.
Echo: ToggleFlipFlop PORT MAP (reset, IN_FWD_to_XMT_ACK, OUT_XMT_to_FWD_ACK);

-- This is just a dummy device, so the space available is magically always this value.
OUT_XMT_to_FWD_spaceavailable <= "01000000000";

-- I'm XMT, so I don't actually HAVE to send more message back to FWD, but we can come up with a different
-- communication protocol. Right now, we just send them ACKs and our first byte of data until they respond,
-- at which point we send them our second byte and keep doing that until we're done.
   
END dummy_xmt_arch;